package org.hank.compose_yyzs.ui

import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.Checkbox
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.hilt.navigation.compose.hiltViewModel
import org.hank.compose_yyzs.viewmodel.MyTestViewModel

//  ┏┓　　　┏┓
//┏┛┻━━━┛┻┓
//┃　　　　　　　┃
//┃　　　━　　　┃
//┃　┳┛　┗┳　┃
//┃　　　　　　　┃
//┃　　　┻　　　┃
//┃　　　　　　　┃
//┗━┓　　　┏━┛
//    ┃　　　┃                  神兽保佑
//    ┃　　　┃                  永无BUG！
//    ┃　　　┗━━━┓
//    ┃　　　　　　　┣┓
//    ┃　　　　　　　┏┛
//    ┗┓┓┏━┳┓┏┛
//      ┃┫┫　┃┫┫
//      ┗┻┛　┗┻┛
/**
 *@auth: Hank
 *邮箱: cs16xiaoc1@163.com
 *创建时间: 2023/6/5 9:19
 *描述:
 */

@Composable
fun ItemSelected(name: String, isSelected: Boolean, onSelect: (Boolean) -> Unit) {
    Row {
        Text(text = name, modifier = Modifier.weight(1f))
        Checkbox(checked = isSelected, onCheckedChange = onSelect)
    }
}

@Composable
fun LazyColumnItems(
    lists: List<TestItem>,
    onCheckChange: (TestItem, Boolean) -> Unit
) {
    LazyColumn {
        items(items = lists) {
            ItemSelected(
                name = it.label,
                isSelected = it.checked,
                onSelect = { checked -> onCheckChange(it, checked) }
            )
        }
    }
}

@Composable
fun TestITemScreen() {
    var viewModel: MyTestViewModel = hiltViewModel()
    LazyColumnItems(
        lists = viewModel.testItems,
        onCheckChange = { item, check -> viewModel.onValueChange(item, check) })
}

class TestItem(var id: Int, var label: String, var isSelected: Boolean = false) {
    var checked by mutableStateOf(isSelected)
}